package com.ruoyi.common.config.websockert3;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author Fql18
 * @version 1.0
 * @date 2025-08-19 23:26
 * @description
 */
@Configuration
@EnableWebSocket
public class WebSocketServerConfig implements WebSocketConfigurer {
	@Bean
	public WebSocketHandler webSocketHandler() {
		return new WebSocketServerHandler();
	}

	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		registry
			.addHandler(webSocketHandler(), "/ws")//添加处理器并指定WebSocket的endpoint端点
			.setAllowedOrigins("*"); //允许跨域访问
	}
}
